package com.itlong.cloud.controller.sdkV1.cloud.elevator.server;

import com.itlong.cloud.POJO.DTO.app.AppCallLiftSaveDTO;
import com.itlong.cloud.POJO.DTO.property.IotCloudElevatorStateDTO;
import com.itlong.cloud.POJO.DTO.sdk.*;
import com.itlong.cloud.POJO.DTO.sdk.CloudElevatorSDKGetByDeviceUniqueDTO;
import com.itlong.cloud.POJO.DTO.sdk.CloudElevatorSDKServerGetElevatorPageDTO;
import com.itlong.cloud.POJO.DTO.sdk.CloudElevatorSDKServerSendCommandDTO;
import com.itlong.cloud.POJO.DTO.sdk.CloudElevatorSDKServerSetUrlDTO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.sdk.CloudElevatorSDKGetByDeviceUniqueVO;
import com.itlong.cloud.abstracts.BaseController;
import com.itlong.cloud.annotation.LoggerInfo;
import com.itlong.cloud.constants.LogDescConstant;
import com.itlong.cloud.constants.RedisConstant;
import com.itlong.cloud.enumerate.CallElevatorRecordSourceEnum;
import com.itlong.cloud.enumerate.CallElevatorSourceTypeEnum;
import com.itlong.cloud.enumerate.CloudElevatorCallTypeEnum;
import com.itlong.cloud.enumerate.CloudElevatorSourceEnum;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.enumerate.ecode.CloudElevarotErrorCodeEnum;
import com.itlong.cloud.enumerate.ecode.SDKErrorCodeEnum;
import com.itlong.cloud.equip.app.IAppDeviceServiceClient;
import com.itlong.cloud.equip.sdk.ICloudElevatorSDKServerCloudServiceClient;
import com.itlong.cloud.project.sdk.ICloudElevatorSDKServerProjectServiceClient;
import com.itlong.cloud.service.RedisService;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.user.app.IAppHomeServiceClient;
import com.itlong.cloud.user.sdk.ICloudTalkSDKServerUserServiceClient;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.node.JsonUtil;
import com.itlong.cloud.utils.words.StringHandlerUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      云电梯SDK服务端云端对旺龙云端控制器
 * </desc>
 *
 * @createDate 2018/12/27
 */
@RestController
@RequestMapping("/cloud/elevator/ctl")
public class CloudElevatorSDKServerCloudController extends BaseController {

    private static Logger LOG = LoggerFactory.getLogger(CloudElevatorSDKServerCloudController.class);

    @Autowired
    private ICloudTalkSDKServerUserServiceClient iCloudTalkSDKServerUserServiceClient;

    @Autowired
    private ICloudElevatorSDKServerCloudServiceClient iCloudElevatorSDKServerCloudServiceClient;

    @Autowired
    private ICloudElevatorSDKServerProjectServiceClient iCloudElevatorSDKServerProjectServiceClient;

    @Autowired
    private IAppDeviceServiceClient iAppDeviceServiceClient;

    @Autowired
    private RedisService redisService;

    @Autowired
    IAppHomeServiceClient iAppHomeServiceClient;

    /**
     * <desc>
     *      查询项目下电梯设备唯一码列表
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2018/12/27
     */
    @ResponseBody
    @PostMapping("/getElevatorList")
    //@LoggerInfo(operateDesc = LogDescConstant.SDK_SERVER_GET_ELEVATOR_DEVICE_UNIQUE_LOG_DESC)
    public Object getElevatorPage(){
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            CloudElevatorSDKServerGetElevatorPageDTO cloudElevatorSDKServerGetElevatorPageDTO = HttpProtocolUtil.parseRequestParamToDTO(CloudElevatorSDKServerGetElevatorPageDTO.class, request);
            String projectId = cloudElevatorSDKServerGetElevatorPageDTO.getProjectId();

            List<String> deviceArr = iCloudElevatorSDKServerCloudServiceClient.getElevatorPage(cloudElevatorSDKServerGetElevatorPageDTO);
            //保存生成操作日志所需信息 详细描述和接口类别
            request.setAttribute("remark",projectId + "查询项目下电梯设备唯一码列表");
            request.setAttribute("portType",LogDescConstant.SDK_CLOUD_ELEVATOR_TYPE_LOG_DESC);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),deviceArr);
        } catch (Exception e) {
            throw new DataAccessException("【云电梯SDK_服务端_查询项目下电梯设备唯一码列表】查询项目下电梯设备唯一码列表失败",e);
        }
    }

    /**
     * <desc>
     *      根据设备唯一码查询电梯信息
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2018/12/28
     */
    @ResponseBody
    @PostMapping("/getElevatorInfo")
    //@LoggerInfo(operateDesc = LogDescConstant.SDK_SERVER_GET_ELEVATOR_INFO_LOG_DESC)
    public Object getElevatorInfo(){
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            CloudElevatorSDKGetByDeviceUniqueDTO cloudElevatorSDKGetByDeviceUniqueDTO = HttpProtocolUtil.parseRequestParamToDTO(CloudElevatorSDKGetByDeviceUniqueDTO.class, request);
            String projectId = cloudElevatorSDKGetByDeviceUniqueDTO.getProjectId();

            if (StringUtils.isBlank(cloudElevatorSDKGetByDeviceUniqueDTO.getDeviceUnique())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            CloudElevatorSDKServerGetElevatorPageDTO cloudElevatorSDKServerGetElevatorPageDTO = new CloudElevatorSDKServerGetElevatorPageDTO();
            cloudElevatorSDKServerGetElevatorPageDTO.setAppId(cloudElevatorSDKGetByDeviceUniqueDTO.getAppId());
            cloudElevatorSDKServerGetElevatorPageDTO.setProjectId(cloudElevatorSDKGetByDeviceUniqueDTO.getProjectId());
            List<String> deviceUniques = iCloudElevatorSDKServerCloudServiceClient.getElevatorPage(cloudElevatorSDKServerGetElevatorPageDTO);
            if (deviceUniques == null || deviceUniques.isEmpty()) {
                return new MessageVO(SDKErrorCodeEnum.SDK_SERVER_NO_DEVICE_UNIQUE_ERR.getErrorCode());
            }
            List<String> deviceUniqueParams = StringHandlerUtil.splitStringList(cloudElevatorSDKGetByDeviceUniqueDTO.getDeviceUnique());
            for (String deviceUniqueParam : deviceUniqueParams) {
                if (!deviceUniques.contains(deviceUniqueParam)) {
                    return new MessageVO(SDKErrorCodeEnum.SDK_SERVER_NO_DEVICE_UNIQUE_ERR.getErrorCode());
                }
            }
            List<CloudElevatorSDKGetByDeviceUniqueVO> cloudElevatorSDKGetByDeviceUniqueVOS = iCloudElevatorSDKServerCloudServiceClient.getElevatorInfo(cloudElevatorSDKGetByDeviceUniqueDTO);
            //保存生成操作日志所需信息 详细描述和接口类别
            request.setAttribute("remark",projectId + "根据设备唯一码" + cloudElevatorSDKGetByDeviceUniqueDTO.getDeviceUnique() + "查询电梯信息");
            request.setAttribute("portType",LogDescConstant.SDK_CLOUD_ELEVATOR_TYPE_LOG_DESC);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),cloudElevatorSDKGetByDeviceUniqueVOS);
        } catch (Exception e) {
            throw new DataAccessException("【云电梯SDK_服务端_根据设备唯一码查询电梯信息】根据设备唯一码查询电梯信息失败",e);
        }
    }

    /**
     * <desc>
     *      设置信息变更路由和状态上报路由
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author Juguang.S
     * @createDate 2018/12/27
     */
    @ResponseBody
    @PostMapping("/setUrl")
    @LoggerInfo(operateDesc = LogDescConstant.SDK_SERVER_SET_INFO_MODIFY_URL_LOG_DESC)
    public Object setUrl(){
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            CloudElevatorSDKServerSetUrlDTO cloudElevatorSDKServerSetUrlDTO = HttpProtocolUtil.parseRequestParamToDTO(CloudElevatorSDKServerSetUrlDTO.class, request);
            String appId = cloudElevatorSDKServerSetUrlDTO.getAppId();
            String projectId = cloudElevatorSDKServerSetUrlDTO.getProjectId();

            iCloudElevatorSDKServerProjectServiceClient.setUrl(cloudElevatorSDKServerSetUrlDTO);
            //保存生成操作日志所需信息 详细描述和接口类别
            request.setAttribute("remark",String.format("%s%s",projectId,LogDescConstant.SDK_SERVER_SET_INFO_MODIFY_URL_LOG_DESC));
            request.setAttribute("portType",LogDescConstant.SDK_CLOUD_ELEVATOR_TYPE_LOG_DESC);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【云电梯SDK_服务端】设置信息变更路由和状态上报路由失败",e);
        }
    }

    /**
     * <desc>
     *      发送开门关门指令
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author Juguang.S
     * @createDate 2018/12/28
     */
    @ResponseBody
    @PostMapping("/sendOpenAndCloseDoor")
    @LoggerInfo(operateDesc = LogDescConstant.SDK_SERVER_SEND_OPEN_CLOSE_DOOR_LOG_DESC)
    public Object sendOpenAndCloseDoor(){
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            CloudElevatorSDKServerSendCommandDTO cloudElevatorSDKServerSendCommandDTO = HttpProtocolUtil.parseRequestParamToDTO(CloudElevatorSDKServerSendCommandDTO.class, request);
            Integer effectiveTime = cloudElevatorSDKServerSendCommandDTO.getEffectiveTime();
            if (effectiveTime == null) {
                effectiveTime = 1;
            }
            if (effectiveTime < 0 || effectiveTime > 99) {
                return new MessageVO(SDKErrorCodeEnum.SDK_SERVER_EFFECTIVE_TIME_OUT_ERR.getErrorCode());
            }

            CloudElevatorSDKServerGetElevatorPageDTO cloudElevatorSDKServerGetElevatorPageDTO = new CloudElevatorSDKServerGetElevatorPageDTO();
            cloudElevatorSDKServerGetElevatorPageDTO.setAppId(cloudElevatorSDKServerSendCommandDTO.getAppId());
            cloudElevatorSDKServerGetElevatorPageDTO.setProjectId(cloudElevatorSDKServerSendCommandDTO.getProjectId());
            List<String> deviceUniques = iCloudElevatorSDKServerCloudServiceClient.getElevatorPage(cloudElevatorSDKServerGetElevatorPageDTO);
            if (deviceUniques == null || deviceUniques.isEmpty() || !deviceUniques.contains(cloudElevatorSDKServerSendCommandDTO.getDeviceUnique())) {
                return new MessageVO(SDKErrorCodeEnum.SDK_SERVER_NO_DEVICE_UNIQUE_ERR.getErrorCode());
            }

            if(cloudElevatorSDKServerSendCommandDTO.getType()==1){
                iAppDeviceServiceClient.cloudElevatorCall(cloudElevatorSDKServerSendCommandDTO.getDeviceUnique(),
                        CloudElevatorSourceEnum.ITLONG_CLOUD_ELEVATOR.getDescription(),
                        null,null,null, CloudElevatorCallTypeEnum.OPEN.getType(),effectiveTime,CallElevatorSourceTypeEnum.ROBOT.getType(),null,null,null, 1, cloudElevatorSDKServerSendCommandDTO.getUpDown(), null, "");
            }
            if(cloudElevatorSDKServerSendCommandDTO.getType()==2){
                iAppDeviceServiceClient.cloudElevatorCall(cloudElevatorSDKServerSendCommandDTO.getDeviceUnique(),
                        CloudElevatorSourceEnum.ITLONG_CLOUD_ELEVATOR.getDescription(),
                        null,null,null, CloudElevatorCallTypeEnum.CLOSE.getType(),effectiveTime,CallElevatorSourceTypeEnum.ROBOT.getType(),null,null,null, 1, cloudElevatorSDKServerSendCommandDTO.getUpDown(), null, "");
            }
            //判断电梯当前状态是否是开门，如果是开门则返回成功，否则返回失败
            boolean isOpen = false;
            int count = 0;
            while(count<6){
                Thread.sleep(500);
                IotCloudElevatorStateDTO dto = JsonUtil.toObject(redisService.getKeysForDevice(RedisConstant.REDIS_IOT_CLOUD_ELEVATOR_STATE_CACHE +
                        cloudElevatorSDKServerSendCommandDTO.getDeviceUnique()),IotCloudElevatorStateDTO.class);
                if(dto != null && StringUtils.isNotBlank(dto.getFrontDoor()) && (dto.getFrontDoor().equals("1") ||
                        dto.getFrontDoor().equals("3") || dto.getFrontDoor().equals("4"))){
                    isOpen = true;
                    break;
                }else{
                    //如从缓存中读取不到电梯的信息触发iot发送电梯控制指令
                    iAppDeviceServiceClient.getCloudElevatorState(cloudElevatorSDKServerSendCommandDTO.getDeviceUnique(), "");
                }
                count++;
            }
            Map<String,Object> result = new HashMap<>();
            result.put("isOpen",isOpen+"");
            //保存生成操作日志所需信息 详细描述和接口类别
            request.setAttribute("remark",String.format("%s%s%s","设备唯一码：",cloudElevatorSDKServerSendCommandDTO.getDeviceUnique(),LogDescConstant.SDK_SERVER_SEND_OPEN_CLOSE_DOOR_LOG_DESC));
            request.setAttribute("portType",LogDescConstant.SDK_CLOUD_ELEVATOR_TYPE_LOG_DESC);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),result);
        } catch (Exception e) {
            throw new DataAccessException("【云电梯SDK_服务端】发送开门关门指令失败",e);
        }
    }

    /**
     * <desc>
     *      电梯楼层开放或登记
     * <desc/>
     *
     * @return
     * @author Jiaqi.X
     * @createDate 2019/08/15
     */
    @RequestMapping(value = "/openOrAutoRegister",method = RequestMethod.POST)
    @LoggerInfo(operateDesc = LogDescConstant.SDK_ROBOT_CALL_ELEVATOR)
    @ResponseBody
    public Object openOrAutoRegister() {
        try {
            HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
            CloudElevatorSDKOpenOrAutoRegisterDTO cloudElevatorSDKOpenOrAutoRegisterDTO =
                    HttpProtocolUtil.parseRequestParamToDTO(CloudElevatorSDKOpenOrAutoRegisterDTO.class, request);
            if (StringUtils.isEmpty(cloudElevatorSDKOpenOrAutoRegisterDTO.getProjectId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            //获取真实楼层
            Map<String,Object> floor = iCloudElevatorSDKServerCloudServiceClient.getFloorNumAndNaturalFloorByLogicFloor(cloudElevatorSDKOpenOrAutoRegisterDTO.getFloors(),
                    cloudElevatorSDKOpenOrAutoRegisterDTO.getDeviceUnique());
            if(floor ==null || floor.get("floors") ==null || floor.get("naturals") == null){
                return new MessageVO(CloudElevarotErrorCodeEnum.CLOUD_FLOOR_ERROR.getErrorCode());
            }
            //调用IOT呼梯
            iAppDeviceServiceClient.openOrAutoRegister(cloudElevatorSDKOpenOrAutoRegisterDTO.getDeviceUnique(),
                    CloudElevatorSourceEnum.ITLONG_CLOUD_ELEVATOR.getDescription(),
                    floor.get("floors").toString(),  CloudElevatorCallTypeEnum.IN.getType(),cloudElevatorSDKOpenOrAutoRegisterDTO.getSeconds(), CallElevatorSourceTypeEnum.ROBOT.getType(), null, null);
            //保存生成操作日志所需信息 详细描述和接口类别
            request.setAttribute("remark",cloudElevatorSDKOpenOrAutoRegisterDTO.getProjectId() + "开放或登记楼层");
            request.setAttribute("portType",LogDescConstant.SDK_CLOUD_ELEVATOR_TYPE_LOG_DESC);
            //装配呼梯记录对象
            AppCallLiftSaveDTO saveDTO = new AppCallLiftSaveDTO();
            saveDTO.setDeviceUnique(cloudElevatorSDKOpenOrAutoRegisterDTO.getDeviceUnique());
            saveDTO.setToFloor(floor.get("naturals").toString());
            saveDTO.setProjectId(cloudElevatorSDKOpenOrAutoRegisterDTO.getProjectId());
            saveDTO.setSource(CallElevatorRecordSourceEnum.ROBOT.getType());
            saveDTO.setUserId(cloudElevatorSDKOpenOrAutoRegisterDTO.getAppId());
            iAppHomeServiceClient.saveCallLiftRecord(saveDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【云电梯SDK服务端_SDKgetElevatorKey】呼叫电梯异常", e);
        }
    }

    /**
     * <desc>
     *      打开关闭上报状态
     * <desc/>
     *
     * @return
     * @author Jiaqi.X
     * @createDate 2019-01-03
     */
    @ResponseBody
    @PostMapping("/openOrCloseStateReport")
    @LoggerInfo(operateDesc = LogDescConstant.SDK_SERVER_OPEN_OR_CLOSE_DESC)
    public Object openOrCloseStateReport() {
        try {
            HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
            CloudElevatorSDKStateReportDTO cloudElevatorSDKStateReportDTO =
                    HttpProtocolUtil.parseRequestParamToDTO(CloudElevatorSDKStateReportDTO.class, request);
            if (StringUtils.isEmpty(cloudElevatorSDKStateReportDTO.getProjectId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            //判断是否有url等参数
            Map<String,Object> map = iCloudElevatorSDKServerCloudServiceClient.getReportInfo(cloudElevatorSDKStateReportDTO.getAppId(),
                    cloudElevatorSDKStateReportDTO.getAppSecret(),cloudElevatorSDKStateReportDTO.getProjectId());
            if(map == null || map.get("url") == null){
                return new MessageVO(CloudElevarotErrorCodeEnum.CLOUD_URL_ERROR.getErrorCode());
            }
            //打开关闭上报状态
            iCloudElevatorSDKServerCloudServiceClient.setOpenOrCloseStateReport(cloudElevatorSDKStateReportDTO);
            //保存生成操作日志所需信息 详细描述和接口类别
            request.setAttribute("remark",cloudElevatorSDKStateReportDTO.getProjectId() + "打开关闭上报状态");
            request.setAttribute("portType",LogDescConstant.SDK_CLOUD_ELEVATOR_TYPE_LOG_DESC);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【云对讲SDK服务端_SDKgetElevatorKey】打开关闭上报状态异常", e);
        }
    }

    /**
     * <desc>
     *      呼叫电梯
     * <desc/>
     *
     * @return
     * @author Jiaqi.X
     * @createDate 2019-01-03
     */
    @RequestMapping(value = "/callElevator",method = RequestMethod.POST)
    @LoggerInfo(operateDesc = LogDescConstant.SDK_SEVER_CALL_ELEVATOR)
    @ResponseBody
    public Object callElevator() {
        try {
            HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
            CloudElevatorSDKCallElevatorDTO cloudElevatorSDKCallElevatorDTO =
                    HttpProtocolUtil.parseRequestParamToDTO(CloudElevatorSDKCallElevatorDTO.class, request);
            if (StringUtils.isEmpty(cloudElevatorSDKCallElevatorDTO.getProjectId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            //获取真实楼层
            Map<String,Object> floor = iCloudElevatorSDKServerCloudServiceClient.getFloorNumByLogicFloor(cloudElevatorSDKCallElevatorDTO.getFromFloor(),
                    cloudElevatorSDKCallElevatorDTO.getToFloor(),cloudElevatorSDKCallElevatorDTO.getDeviceUnique());
            if(floor == null || floor.get("goFloor") == null || floor.get("fromFloor") == null){
                return new MessageVO(CloudElevarotErrorCodeEnum.CLOUD_FLOOR_ERROR.getErrorCode());
            }
            //调用IOT呼梯
            iAppDeviceServiceClient.cloudElevatorCall(cloudElevatorSDKCallElevatorDTO.getDeviceUnique(),
                    CloudElevatorSourceEnum.ITLONG_CLOUD_ELEVATOR.getDescription(),
                    floor.get("goFloor").toString(),floor.get("fromFloor").toString(),null,
                    CloudElevatorCallTypeEnum.OUT.getType(),null, CallElevatorSourceTypeEnum.CLOUD.getType(),
                    null,null,cloudElevatorSDKCallElevatorDTO.getCtrElevator(), 1, cloudElevatorSDKCallElevatorDTO.getUpDown(), null, "");


            //保存生成操作日志所需信息 详细描述和接口类别
            request.setAttribute("remark",cloudElevatorSDKCallElevatorDTO.getProjectId() + "呼叫电梯");
            request.setAttribute("portType",LogDescConstant.SDK_CLOUD_ELEVATOR_TYPE_LOG_DESC);
            //装配呼梯记录对象
            AppCallLiftSaveDTO saveDTO = new AppCallLiftSaveDTO();
            saveDTO.setDeviceUnique(cloudElevatorSDKCallElevatorDTO.getDeviceUnique());
            saveDTO.setFromFloor(cloudElevatorSDKCallElevatorDTO.getFromFloor());
            saveDTO.setToFloor(cloudElevatorSDKCallElevatorDTO.getToFloor());
            saveDTO.setProjectId(cloudElevatorSDKCallElevatorDTO.getProjectId());
            saveDTO.setSource(CallElevatorRecordSourceEnum.CLOUD.getType());
            saveDTO.setUserId(cloudElevatorSDKCallElevatorDTO.getAppId());
            iAppHomeServiceClient.saveCallLiftRecord(saveDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【云对讲SDK服务端_SDKgetElevatorKey】呼叫电梯异常", e);
        }
    }

    /**
     * <desc>
     *      设置专梯模式
     * <desc/>
     *
     * @return
     * @author Jiaqi.X
     * @createDate 2019-01-03
     */
    @RequestMapping(value = "/setCloudElevatorSpecialUseModel",method = RequestMethod.POST)
    @LoggerInfo(operateDesc = LogDescConstant.SDK_SEVER_SET_CLOUD_ELEVATOR_SPECIAL_USE_MODEL)
    @ResponseBody
    public Object setCloudElevatorSpecialUseModel() {
        try {
            HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
            CloudElevatorSDKSpecialUseModelDTO cloudElevatorSDKSpecialUseModelDTO =
                    HttpProtocolUtil.parseRequestParamToDTO(CloudElevatorSDKSpecialUseModelDTO.class, request);
            if (StringUtils.isEmpty(cloudElevatorSDKSpecialUseModelDTO.getProjectId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            iAppDeviceServiceClient.setCloudElevatorSpecialUseModel(cloudElevatorSDKSpecialUseModelDTO.getDeviceUnique(),cloudElevatorSDKSpecialUseModelDTO.getModel());
            //保存生成操作日志所需信息 详细描述和接口类别
            request.setAttribute("remark",cloudElevatorSDKSpecialUseModelDTO.getProjectId() + "设置专梯模式");
            request.setAttribute("portType",LogDescConstant.SDK_CLOUD_ELEVATOR_TYPE_LOG_DESC);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【云对讲SDK服务端_SDKgetElevatorKey】设置专梯模式异常", e);
        }
    }
}
